package com.wdcg;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class ApplicationSharedPreferences {
	final public static String FIRST_INIT_AFTER_INSTALL = "FirstInitAfterInstall";
	final public static String PREF_ID = "DWARF";
	final public static String NEW_GAME = "newGame";
	final public static String NUMBER_OF_DWARFS = "numberOfDwarfs";
	public static SharedPreferences sp;
	
	
	public static void init(Context context){
			sp = context.getSharedPreferences(PREF_ID,
				Activity.MODE_PRIVATE);
	}
	
	public static boolean isDatabaseCreated(){
		return sp.getBoolean(FIRST_INIT_AFTER_INSTALL, false);
	}
	
	public static void setDatabaseIsCreated(){
		SharedPreferences.Editor preferencesEditor = sp.edit();
		preferencesEditor.putBoolean(FIRST_INIT_AFTER_INSTALL, true);
		preferencesEditor.commit();
	}
	
	public static boolean isNewGame(){
		return sp.getBoolean(NEW_GAME, true);
	}
	
	public static void setNewGamePlayed(){
		SharedPreferences.Editor preferencesEditor = sp.edit();
		preferencesEditor.putBoolean(NEW_GAME, false);
		preferencesEditor.commit();
	}
	
	public static int getNumberOfDwarfs(){
		return sp.getInt(NUMBER_OF_DWARFS, 0);
	}
	
	public static void setNumberOfDwarfs(int number){
		SharedPreferences.Editor preferencesEditor = sp.edit();
		preferencesEditor.putInt(NUMBER_OF_DWARFS, number);
		preferencesEditor.commit();
	}
	
	public static void incrementNumberOfDwarves() {
		SharedPreferences.Editor preferencesEditor = sp.edit();
		preferencesEditor.putInt(NUMBER_OF_DWARFS, sp.getInt(NUMBER_OF_DWARFS, 0)+1);
		preferencesEditor.commit();
	}

	public static void decrementNumberOfDwarves() {
		SharedPreferences.Editor preferencesEditor = sp.edit();
		int number = sp.getInt(NUMBER_OF_DWARFS, 0)-1;
		if(number < 1)
			number = 1;
		preferencesEditor.putInt(NUMBER_OF_DWARFS, number);
		preferencesEditor.commit();		
	}
}
